package models.dao;

import java.sql.ResultSet;
import model.pojo.Employee;
import models.util.MD5;
import models.util.MySqlDataAccessHelper;

public class LoginSystem {
	public Employee checkLogin(String username,String pass,String databasename){
		MySqlDataAccessHelper mysql = new MySqlDataAccessHelper();
		Employee em = null;
		try {
			mysql.open(databasename);
			String sql="select IDEmployee,UserName,Password,IDRole from employee where UserName='"+username+"' and Password='"+MD5.encrypt(pass)+"' and State=1";
			ResultSet rs = mysql.executeQuery(sql);
			while (rs.next()) {
				em= new  Employee(rs.getString("IDEmployee"), rs.getInt("IDRole"), rs.getString("UserName"), rs.getString("Password"));
			}
			rs.close();
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			try{
				mysql.close();
			}catch(Exception ex){
				ex.printStackTrace();
			}
		}
		return em;
	}	
}